package com.liangzhong.manager
{
	import com.liangzhong.constants.DomainConst;
	
	import flash.system.*;
	
	public class DomainManager implements IDomainManager
	{
		private var domains:Object;
		private static var _instance:DomainManager;
		
		public function DomainManager()
		{
			domains = {};
			var curDomain:* = ApplicationDomain.currentDomain;
			domains[DomainConst.CHILDREN] = curDomain;
			domains[DomainConst.CURRENT] = ApplicationDomain.currentDomain;
			return;
		}
		/**
		 * 设置domain
		 * @param key
		 * @param dMain
		 * 
		 */		 
		public function setDomain(key:String,dMain:ApplicationDomain):void
		{
			domains[key] = dMain;
		}
		/**
		 * 获取domain
		 * @param key
		 * @return 
		 * 
		 */		
		public function getDomain(key:String) : ApplicationDomain
		{
			return domains[key];
		}
		/**
		 *删除domain 
		 * @param key
		 * 
		 */		
		public function removeDomain(key:String):ApplicationDomain
		{
			var domain:ApplicationDomain = domains[key];
			delete domains[key];
			return domain;
		}
		
		public static function initilaize() : void
		{
			if (_instance == null)
			{
				_instance = new DomainManager();
			}
			return;
		}
		
		public static function getInstance() : DomainManager
		{
			if (_instance == null)
			{
				_instance = new DomainManager();
			}
			return _instance;
		}
		
	}
}